package com.zkt.auth.domain.service.impl;

import com.zkt.auth.common.enums.AuthStatusEnum;
import com.zkt.auth.domain.convert.AuthRoleConverter;
import com.zkt.auth.domain.entity.AuthRoleBO;
import com.zkt.auth.domain.service.AuthRoleDomainService;
import com.zkt.auth.infra.basic.entity.AuthRole;
import com.zkt.auth.infra.basic.service.IAuthRoleService;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @author 赵开泰
 * @program jc-club
 * @date 2024/9/30
 * @description 角色领域服务
 **/

@Service
@Slf4j
public class AuthRoleDomainServiceImpl implements AuthRoleDomainService {
	
	@Resource
	private IAuthRoleService authRoleService;
	
	/**
	 * 新增角色
	 *
	 * @param authRoleBO 角色信息
	 * @return 是否成功
	 */
	@Override
	public Boolean add(AuthRoleBO authRoleBO) {
		AuthRole authRole = AuthRoleConverter.INSTANCE.convertBoToAuthRole(authRoleBO);
		
		if (authRole.getStatus() == null) {
			authRole.setStatus(AuthStatusEnum.OPEN.getCode());
		}
		
		return authRoleService.save(authRole);
	}
	
	/**
	 * 修改角色
	 *
	 * @param authRoleBO 角色信息
	 * @return 是否成功
	 */
	@Override
	public Boolean update(AuthRoleBO authRoleBO) {
		AuthRole authRole = AuthRoleConverter.INSTANCE.convertBoToAuthRole(authRoleBO);
		return authRoleService.updateById(authRole);
	}
	
	/**
	 * 删除角色
	 *
	 * @param authRoleBO 角色信息
	 * @return 是否成功
	 */
	@Override
	public Boolean delete(AuthRoleBO authRoleBO) {
		AuthRole authRole = AuthRoleConverter.INSTANCE.convertBoToAuthRole(authRoleBO);
		return authRoleService.removeById(authRole);
	}
	
	/**
	 * 角色启用/禁用
	 *
	 * @param authRoleBO 角色信息
	 * @return 是否成功
	 */
	@Override
	public Boolean changeStatus(AuthRoleBO authRoleBO) {
		return this.update(authRoleBO);
	}
}